/*
 * Course:    CS 590 Web Services
 * Semseter:  Spring 2009
 * Professor: Sedlemeyer
 * Project:   CHEAT (Code Help Educational Assignment Tool)
 * Due Date:  May 1, 2009
 * Team:      Sarcasm
 *            (Baker, Jason; Mitchell, Robin; Shie, Keith)
 */

package cheat.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Define the types of assignments.
 *
 * <p>The types are:<ul>
 * <li>program</li>
 * <li>class</li>
 * <li>method</li>
 * <li>function</li>
 * <li>procedure</li>
 * <li>block</li>
 * <li>statement</li>
 * <li>declaration</li>
 * <li>other</li>
 * </ul></p>
 *
 * @author Keith Shie
 */
@Entity
@Table(name = "asgn_type")
@NamedQueries({@NamedQuery(name = "AssignmentType.findAll", query = "SELECT a FROM AssignmentType a"),
        @NamedQuery(name = "AssignmentType.findByAsgnTypCode", query =
        "SELECT a FROM AssignmentType a WHERE a.assignmentTypeCode = :assignmentTypeCode"),
        @NamedQuery(name = "AssignmentType.findByDescription", query =
        "SELECT a FROM AssignmentType a WHERE a.description = :description")})
public class AssignmentType implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @Basic(optional = false)
  @Column(name = "asgn_typ_code", nullable = false, length = 8)
  private String assignmentTypeCode;
  @Basic(optional = false)
  @Column(name = "description", nullable = false, length = 120)
  private String description;
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "assignmentTypeCode",fetch=FetchType.LAZY)
  private Collection<AssignmentProperty> asgnPropCollection;

  public AssignmentType() {
  }

  public AssignmentType(String assignmentTypeCode) {
    this.assignmentTypeCode = assignmentTypeCode;
  }

  public AssignmentType(String assignmentTypeCode, String description) {
    this.assignmentTypeCode = assignmentTypeCode;
    this.description = description;
  }

  public String getAssignmentTypeCode() {
    return assignmentTypeCode;
  }

  public void setAssignmentTypeCode(String assignmentTypeCode) {
    this.assignmentTypeCode = assignmentTypeCode;
  }

  public String getDescription() {
    return description;
  }

  public void setDescription(String description) {
    this.description = description;
  }

  public Collection<AssignmentProperty> getAsgnPropCollection() {
    return asgnPropCollection;
  }

  public void setAsgnPropCollection(Collection<AssignmentProperty> asgnPropCollection) {
    this.asgnPropCollection = asgnPropCollection;
  }

  @Override
  public int hashCode() {
    int hash = 0;
    hash += (assignmentTypeCode != null ? assignmentTypeCode.hashCode() : 0);
    return hash;
  }

  @Override
  public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof AssignmentType)) {
      return false;
    }
    AssignmentType other = (AssignmentType) object;
    if ((this.assignmentTypeCode == null && other.assignmentTypeCode != null) || (this.assignmentTypeCode != null && !this.assignmentTypeCode.equals(other.assignmentTypeCode))) {
      return false;
    }
    return true;
  }

  @Override
  public String toString() {
    return "cheat.entities.AsgnType[asgnTypCode=" + assignmentTypeCode + "]";
  }

}
